using System.Runtime.InteropServices;
using System.Text;

namespace System.Utility.Win32
{
	public class Win32
	{
		public Win32()
		{
		}

		[DllImport("kernel32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern void CloseHandle(IntPtr hObject);

		[DllImport("gdi32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern bool DeleteObject(IntPtr hObject);

		[DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern IntPtr FindWindow(string className, string windowName);

		public static IntPtr FindWindowByClass(string className)
		{
			return FindWindow(null, className);
		}

		public static IntPtr FindWindowByClass(IntPtr handlerParent, string childClassName)
		{
			return FindWindowEx(handlerParent, 0, childClassName, null);
		}

		public static IntPtr FindWindowByClass(IntPtr handlerParent, int handlerChildAfter, string childClassName)
		{
			return FindWindowEx(handlerParent, handlerChildAfter, childClassName, null);
		}

		public static IntPtr FindWindowByClass(int handlerChildAfter, string childClassName)
		{
			return FindWindowEx(IntPtr.Zero, handlerChildAfter, childClassName, null);
		}

		public static IntPtr FindWindowByText(string windowName)
		{
			return FindWindow(null, windowName);
		}

		public static IntPtr FindWindowByText(IntPtr handlerParent, string childWindowName)
		{
			return FindWindowEx(handlerParent, 0, null, childWindowName);
		}

		public static IntPtr FindWindowByText(IntPtr handlerParent, int handlerChildAfter, string childWindowName)
		{
			return FindWindowEx(handlerParent, handlerChildAfter, null, childWindowName);
		}

		[DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern IntPtr FindWindowEx(IntPtr handlerParent, int handlerChildAfter, string childClassName, string childWindowName);

		[DllImport("kernel32.dll", CharSet=CharSet.None, EntryPoint="GetDiskFreeSpaceExA", ExactSpelling=false)]
		public static extern int GetDiskFreeSpaceEx(string lpRootPathName, out long lpFreeBytesAvailable, out long lpTotalNumberOfBytes, out long lpTotalNumberOfFreeBytes);

		[DllImport("kernel32", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

		[DllImport("kernel32", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, byte[] lpReturnedString, uint nSize, string lpFileName);

		public static bool HideWindow(IntPtr handlerWindow)
		{
			return ShowWindow(handlerWindow, 0);
		}

		[DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern bool SetWindowLong(IntPtr handlerWindow, int nIndex, int newLong);

		[DllImport("user32.dll", CharSet=CharSet.None, ExactSpelling=false)]
		private static extern bool ShowWindow(IntPtr handlerWindow, uint cmd);

		[DllImport("kernel32", CharSet=CharSet.None, ExactSpelling=false)]
		public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
	}
}